package cn.edu.scau.dao;

import cn.edu.scau.entity.LiveInRegister;

import java.util.List;

import org.apache.ibatis.annotations.CacheNamespace;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

@Mapper
@CacheNamespace
public interface LiveInRegisterMapper {
    @Delete({
        "delete from liveinregister",
        "where customerID = #{customerid,jdbcType=INTEGER}",
          "and bookingID = #{bookingid,jdbcType=INTEGER}",
          "and bedID = #{bedid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(@Param("customerid") Integer customerid, @Param("bookingid") Integer bookingid, @Param("bedid") Integer bedid);

    @Insert({
        "insert into liveinregister (customerID, bookingID, ",
        "bedID, liveinDate, ",
        "expectedLiveoutDate, actuallyLiveoutDate, ",
        "registerUseflag)",
        "values (#{customerid,jdbcType=INTEGER}, #{bookingid,jdbcType=INTEGER}, ",
        "#{bedid,jdbcType=INTEGER}, #{liveindate,jdbcType=DATE}, ",
        "#{expectedliveoutdate,jdbcType=DATE}, #{actuallyliveoutdate,jdbcType=DATE}, ",
        "#{registeruseflag,jdbcType=BIT})"
    })
    int insert(LiveInRegister record);

    @InsertProvider(type=LiveInRegisterSqlProvider.class, method="insertSelective")
    int insertSelective(LiveInRegister record);

    @Select({
        "select",
        "customerID, bookingID, bedID, liveinDate, expectedLiveoutDate, actuallyLiveoutDate, ",
        "registerUseflag",
        "from liveinregister",
        "where customerID = #{customerid,jdbcType=INTEGER}",
          "and bookingID = #{bookingid,jdbcType=INTEGER}",
          "and bedID = #{bedid,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="customerID", property="customerid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="bookingID", property="bookingid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="bedID", property="bedid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="liveinDate", property="liveindate", jdbcType=JdbcType.DATE),
        @Result(column="expectedLiveoutDate", property="expectedliveoutdate", jdbcType=JdbcType.DATE),
        @Result(column="actuallyLiveoutDate", property="actuallyliveoutdate", jdbcType=JdbcType.DATE),
        @Result(column="registerUseflag", property="registeruseflag", jdbcType=JdbcType.BIT)
    })
    LiveInRegister selectByPrimaryKey(@Param("customerid") Integer customerid, @Param("bookingid") Integer bookingid, @Param("bedid") Integer bedid);

    @Select({
        "select",
        "customerID, bookingID, bedID, liveinDate, expectedLiveoutDate, actuallyLiveoutDate, ",
        "registerUseflag",
        "from liveinregister"
    })
    @Results({
        @Result(column="customerID", property="customerid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="bookingID", property="bookingid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="bedID", property="bedid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="liveinDate", property="liveindate", jdbcType=JdbcType.DATE),
        @Result(column="expectedLiveoutDate", property="expectedliveoutdate", jdbcType=JdbcType.DATE),
        @Result(column="actuallyLiveoutDate", property="actuallyliveoutdate", jdbcType=JdbcType.DATE),
        @Result(column="registerUseflag", property="registeruseflag", jdbcType=JdbcType.BIT)
    })
    List<LiveInRegister> selectAll();

    @Select({
        "select",
        "customerID, bookingID, bedID, liveinDate, expectedLiveoutDate, actuallyLiveoutDate, ",
        "registerUseflag",
        "from liveinregister",
        "where customerID = #{customerid,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="customerID", property="customerid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="bookingID", property="bookingid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="bedID", property="bedid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="liveinDate", property="liveindate", jdbcType=JdbcType.DATE),
        @Result(column="expectedLiveoutDate", property="expectedliveoutdate", jdbcType=JdbcType.DATE),
        @Result(column="actuallyLiveoutDate", property="actuallyliveoutdate", jdbcType=JdbcType.DATE),
        @Result(column="registerUseflag", property="registeruseflag", jdbcType=JdbcType.BIT)
    })
    List<LiveInRegister> selectByCustomerID(@Param("customerid") Integer customerid);
    
    @Select({
        "select",
        "customerID, bookingID, bedID, liveinDate, expectedLiveoutDate, actuallyLiveoutDate, ",
        "registerUseflag",
        "from liveinregister",
        "where customerID = #{customerid,jdbcType=INTEGER}",
        "and registerUseflag != false"
    })
    @Results({
        @Result(column="customerID", property="customerid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="bookingID", property="bookingid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="bedID", property="bedid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="liveinDate", property="liveindate", jdbcType=JdbcType.DATE),
        @Result(column="expectedLiveoutDate", property="expectedliveoutdate", jdbcType=JdbcType.DATE),
        @Result(column="actuallyLiveoutDate", property="actuallyliveoutdate", jdbcType=JdbcType.DATE),
        @Result(column="registerUseflag", property="registeruseflag", jdbcType=JdbcType.BIT)
    })
    List<LiveInRegister> findLatestById(@Param("customerid") Integer customerid);
    
    @UpdateProvider(type=LiveInRegisterSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(LiveInRegister record);

    @Update({
        "update liveinregister",
        "set liveinDate = #{liveindate,jdbcType=DATE},",
          "expectedLiveoutDate = #{expectedliveoutdate,jdbcType=DATE},",
          "actuallyLiveoutDate = #{actuallyliveoutdate,jdbcType=DATE},",
          "registerUseflag = #{registeruseflag,jdbcType=BIT}",
        "where customerID = #{customerid,jdbcType=INTEGER}",
          "and bookingID = #{bookingid,jdbcType=INTEGER}",
          "and bedID = #{bedid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(LiveInRegister record);
}